import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
// 表单校验
export const rules = reactive({
  siteId: [required],
  accessUrl: [required],
  pvCount: [required],
  uvCount: [required],
  ipCount: [required],
  dateString: [required],
  accessType: [required]
})

const crudSchemas = reactive<CrudSchema[]>([
  {
    label: 'ID',
    field: 'id',
    isForm: false,
    isTable: false
  },
  {
    label: '站点ID',
    field: 'siteId',
    isSearch: false,
    isTable: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '来源',
    field: 'statName',
    isSearch: false
  },
  {
    label: '访问量',
    field: 'pvCount',
    isSearch: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '访客数',
    field: 'uvCount',
    isSearch: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: 'IP数',
    field: 'ipCount',
    isSearch: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '日期',
    field: 'dateString',
    isSearch: true,
    formatter: dateFormatter,
    isTable: false,
    search: {
      show: true,
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('30 23:59:59')]
      }
    },
    detail: {
      dateFormat: 'YYYY-MM-DD'
    }
  },
  {
    label: '类型(1:访问地址,2:入口地址)',
    field: 'accessType',
    isSearch: false,
    isTable: false,
    form: {
      component: 'SelectV2'
    }
  },
  {
    label: '操作',
    field: 'action',
    isForm: false,
    isTable: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
